<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑地址</title>
</head>
<body>
<div id="editAddress">
    <p>
        收&nbsp;&nbsp;件&nbsp;&nbsp;&nbsp;人&nbsp;:&nbsp;<input type="text" v-model="showAddress.addressee">
    </p>
    <p>
        联&nbsp;系&nbsp;电&nbsp;话:&nbsp;<input type="text" v-model="showAddress.phone">
    </p>
    <p>
        省&nbsp;&nbsp;市&nbsp;&nbsp;&nbsp;区&nbsp;:&nbsp;<input type="text" v-model="showAddress.area">
    </p>
    <p>
        详&nbsp;细&nbsp;地&nbsp;址:&nbsp;<input type="text" v-model="showAddress.address_detail">
    </p>
    <input type="button" value="保存" @click="saveAddress">&nbsp;
    <input type="button" value="返回" @click="returnPages">

</div>
<script src="assets/js/vue.js"></script>
<script src="assets/js/axios.min.js"></script>
<script>
    const addressData = new Vue({
        el: "#editAddress",
        data: {
            showAddress: {
                addressee: "",
                phone: "",
                area: "",
                address_detail: "",
            },
        },
        methods: {
            returnPages() {
                location.href = "invoice-info-manage.html";
            },
            saveAddress() {
                let _this = this;
                let formData = new FormData();
                let start = location.href.split("=");
                let id = start[2];
                //alert(id);
                formData.append("id", id);
                formData.append("addressee", this.showAddress.addressee);
                formData.append("phone", this.showAddress.phone);
                formData.append("area", this.showAddress.area);
                formData.append("address_detail", this.showAddress.address_detail);
                let flag = _this.showAddress.bankName == "" || _this.showAddress.bankAccount == "" || _this.showAddress.phone == "" || _this.showAddress.address == "";
                if (flag) {
                    alert("请输入信息!");
                    location.href = "editAddress.html";
                } else {
                    axios({
                        method: "post",
                        url: "../admin/updateAddressById.ad",
                        data: formData,
                    }).then(function (response) {
                            let data = response.data;
                            if (data.code == 520) {
                                alert(data.msg);
                                location.href = "invoice-info-manage.html";
                            } else {
                                alert(data.msg);
                            }
                        }
                    )
                }
            },
        },
        created() {
            let _this = this;
            let start = location.href.split("=");
            console.log(start);
            let id = start[1].substring(0,start[1].indexOf("&"));
            console.log(id);
            let index = id - 1;
            // 发请求，拿数据
            axios.get("../admin/listAddress.ad").then(function (res) {
                //console.log(res.data);
                _this.showAddress.addressee = res.data.value[index].addressee;
                _this.showAddress.phone = res.data.value[index].phone;
                _this.showAddress.area = res.data.value[index].area;
                _this.showAddress.address_detail = res.data.value[index].address_detail;
            });
        }
    });
</script>
</body>
</html>